<html>
<head>
  <title> Always on Visible Workspace Test - window #2 </title>
</head>
<body style="background-color:rgba(0,0,0,0);">
<h3>Window #2</h3>
<p>This window is <span id="workspaces_status">visible only on this workspace</span></p>
<div>
  <a href="" id="visible-on-all-workspaces">Visible on all workspaces</a>
  <p>Makes the window visible on all workspaces simultaneously.</p>
</div>
<div>
  <a href="" id="only-on-this-desktop">Only on this workspace</a>
  <p>Makes the window visible only on this workspace.</p>
</div>
<p id="output"></p>
<script>
var gui = require('nw.gui');
var win = gui.Window.get();

function setVisibleOnAllWorkspaces(all_workspaces){
  win.setVisibleOnAllWorkspaces(all_workspaces);

  updateStatusText(all_workspaces);

  document.getElementById("output").innerHTML += 
    'called Window.setVisibleOnAllWorkspaces(' + all_workspaces + ');<br/>\n';
}

function updateStatusText(all_workspaces) {
  var statusEl = document.getElementById('workspaces_status');
  var statusText = all_workspaces ? 'visible on all workspaces' : 'visible only on this workspace';
  statusEl.innerText = statusText;
}

document.getElementById('visible-on-all-workspaces').onclick = function (e) { setVisibleOnAllWorkspaces(true); e.preventDefault(); };
document.getElementById('only-on-this-desktop').onclick = function (e) { setVisibleOnAllWorkspaces(false); e.preventDefault(); };

</script>  
</body>
</html>
